package com.itheima.spring.cyclicDependency.config;

import com.itheima.spring.cyclicDependency.bean.UserA;
import com.itheima.spring.cyclicDependency.proxy.MyEnhancer;
import com.itheima.spring.cyclicDependency.proxy.MyProxy;
import net.sf.cglib.proxy.Enhancer;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;

public class CglibProxyBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor {

    @Override
    public Object getEarlyBeanReference(Object bean, String beanName) {
        System.out.println("aop增强:"+beanName);
        if (bean instanceof UserA) {
            MyEnhancer myEnhancer = new MyEnhancer(new MyProxy(),bean);
            Enhancer enhancer = myEnhancer.getEnhancer();
            bean = enhancer.create();
        }
        return bean;
    }


}